<HTML>
<BODY BGCOLOR="white">
<PRE>
<FONT color="green">001</FONT>    package cheesymock;<a name="line.1"></a>
<FONT color="green">002</FONT>    <a name="line.2"></a>
<FONT color="green">003</FONT>    import java.lang.reflect.*;<a name="line.3"></a>
<FONT color="green">004</FONT>    import static cheesymock.MethodUtil.*;<a name="line.4"></a>
<FONT color="green">005</FONT>    <a name="line.5"></a>
<FONT color="green">006</FONT>    /**<a name="line.6"></a>
<FONT color="green">007</FONT>     * &lt;h1&gt;CheesyMock&lt;/h1&gt;<a name="line.7"></a>
<FONT color="green">008</FONT>     *<a name="line.8"></a>
<FONT color="green">009</FONT>     * CheesyMock is a small and simple library for creating mock objects<a name="line.9"></a>
<FONT color="green">010</FONT>     * from Java interfaces. It has but one design goal:<a name="line.10"></a>
<FONT color="green">011</FONT>     *<a name="line.11"></a>
<FONT color="green">012</FONT>     * &lt;blockquote&gt;&lt;i&gt;The user should have to type as little as possible.&lt;/i&gt;<a name="line.12"></a>
<FONT color="green">013</FONT>     * &lt;/blockquote&gt;<a name="line.13"></a>
<FONT color="green">014</FONT>     *<a name="line.14"></a>
<FONT color="green">015</FONT>     * &lt;h2&gt;A Use Case Example&lt;/h2&gt;<a name="line.15"></a>
<FONT color="green">016</FONT>     *<a name="line.16"></a>
<FONT color="green">017</FONT>     * &lt;p&gt; Let's say you're writing an application and want to write some<a name="line.17"></a>
<FONT color="green">018</FONT>     *    unit tests. For one of your tests you need to supply an instance<a name="line.18"></a>
<FONT color="green">019</FONT>     *    of {@link javax.servlet.http.HttpServletRequest}, which puts you<a name="line.19"></a>
<FONT color="green">020</FONT>     *    in kind of pickle. You have no concrete implementation of that<a name="line.20"></a>
<FONT color="green">021</FONT>     *    class, since that's usually provided by a sevlet container. So<a name="line.21"></a>
<FONT color="green">022</FONT>     *    what do you do? Well, you &lt;i&gt;could&lt;/i&gt; write your own simple<a name="line.22"></a>
<FONT color="green">023</FONT>     *    implementation of HttpServletRequest and use that in your test<a name="line.23"></a>
<FONT color="green">024</FONT>     *    case. It's not that hard, especially if you're using one of the<a name="line.24"></a>
<FONT color="green">025</FONT>     *    modern IDEs that can generate most of the code for you.&lt;/p&gt;<a name="line.25"></a>
<FONT color="green">026</FONT>     *<a name="line.26"></a>
<FONT color="green">027</FONT>     * &lt;p&gt; It seems a bit wasteful, though. You know for a fact that your<a name="line.27"></a>
<FONT color="green">028</FONT>     *    test will only ever call a single method (let's say {@link<a name="line.28"></a>
<FONT color="green">029</FONT>     *    javax.sevlet.http.HttpServletRequest#getRequestURI()}) and only<a name="line.29"></a>
<FONT color="green">030</FONT>     *    requires a trivial return value (let's say<a name="line.30"></a>
<FONT color="green">031</FONT>     *    "www.myserver.com/myApp/myServlet/"). Why should you have to<a name="line.31"></a>
<FONT color="green">032</FONT>     *    create a big honkin' class just for that?&lt;/p&gt;<a name="line.32"></a>
<FONT color="green">033</FONT>     *<a name="line.33"></a>
<FONT color="green">034</FONT>     * &lt;p&gt; Well, it turns out you don't have to. With CheesyMock you can<a name="line.34"></a>
<FONT color="green">035</FONT>     *    get an instance of HttpServletRequest just by writing something<a name="line.35"></a>
<FONT color="green">036</FONT>     *    like this:&lt;/p&gt;<a name="line.36"></a>
<FONT color="green">037</FONT>     *<a name="line.37"></a>
<FONT color="green">038</FONT>     * &lt;pre&gt;HttpServletRequest req = Cheesy.mock(HttpServletRequest.class);&lt;/pre&gt;<a name="line.38"></a>
<FONT color="green">039</FONT>     *<a name="line.39"></a>
<FONT color="green">040</FONT>     * &lt;p&gt; Voila! One request instance coming up. But what about the<a name="line.40"></a>
<FONT color="green">041</FONT>     *    return value? We need the call &lt;code&gt;req.getRequestURI()&lt;/code&gt;<a name="line.41"></a>
<FONT color="green">042</FONT>     *    to actually return something useful. Well, in that case we also<a name="line.42"></a>
<FONT color="green">043</FONT>     *    need to supply a &lt;i&gt;delegate&lt;/i&gt; object. If you call a method on<a name="line.43"></a>
<FONT color="green">044</FONT>     *    the mock that's also defined in the delegate (i.e. the name,<a name="line.44"></a>
<FONT color="green">045</FONT>     *    argument list and return type are equivalent), then the delegate<a name="line.45"></a>
<FONT color="green">046</FONT>     *    method will be called and its return value will be returned from<a name="line.46"></a>
<FONT color="green">047</FONT>     *    the mock method call.&lt;/p&gt;<a name="line.47"></a>
<FONT color="green">048</FONT>     *<a name="line.48"></a>
<FONT color="green">049</FONT>     * &lt;p&gt; A delegate object can be any object at all, so for this case we<a name="line.49"></a>
<FONT color="green">050</FONT>     *    define a new class inline:&lt;/p&gt;<a name="line.50"></a>
<FONT color="green">051</FONT>     *<a name="line.51"></a>
<FONT color="green">052</FONT>     * &lt;pre&gt;HttpServletRequest req = Cheesy.mock(HttpServletRequest.class, new Object() {<a name="line.52"></a>
<FONT color="green">053</FONT>     *    public String getRequestURI() {<a name="line.53"></a>
<FONT color="green">054</FONT>     *       return "www.myserver.com/myApp/myServlet";<a name="line.54"></a>
<FONT color="green">055</FONT>     *    }<a name="line.55"></a>
<FONT color="green">056</FONT>     * });&lt;/pre&gt;<a name="line.56"></a>
<FONT color="green">057</FONT>     * <a name="line.57"></a>
<FONT color="green">058</FONT>     * &lt;p&gt; Pretty neat, huh? But we can do even better. CheesyMock doesn't<a name="line.58"></a>
<FONT color="green">059</FONT>     *    care about visibility modifiers on methods, so you can safely<a name="line.59"></a>
<FONT color="green">060</FONT>     *    drop the &lt;code&gt;public&lt;/code&gt;, which makes it a bit<a name="line.60"></a>
<FONT color="green">061</FONT>     *    shorter. Also, CheesyMock supplies a very simple standard<a name="line.61"></a>
<FONT color="green">062</FONT>     *    delegate called (you guessed it) {@link Delegate}, which can be<a name="line.62"></a>
<FONT color="green">063</FONT>     *    used instead of {@link Object}. That in itself doesn't save any<a name="line.63"></a>
<FONT color="green">064</FONT>     *    keystrokes, but Delegate has an alias (well, a subclass really)<a name="line.64"></a>
<FONT color="green">065</FONT>     *    called simply {@link D}. Similarly, {@link Cheesy} also has an<a name="line.65"></a>
<FONT color="green">066</FONT>     *    alias called {@link C} So the statement above could be written<a name="line.66"></a>
<FONT color="green">067</FONT>     *    as:&lt;/p&gt;<a name="line.67"></a>
<FONT color="green">068</FONT>     *<a name="line.68"></a>
<FONT color="green">069</FONT>     * &lt;pre&gt; HttpServletRequest req = C.mock(HttpServletRequest.class, new D() {<a name="line.69"></a>
<FONT color="green">070</FONT>     *    String getRequestURI() {<a name="line.70"></a>
<FONT color="green">071</FONT>     *       return "www.myserver.com/myApp/myServlet";<a name="line.71"></a>
<FONT color="green">072</FONT>     *    }<a name="line.72"></a>
<FONT color="green">073</FONT>     * });&lt;/pre&gt;<a name="line.73"></a>
<FONT color="green">074</FONT>     *<a name="line.74"></a>
<FONT color="green">075</FONT>     * &lt;p&gt; Also, if you want it &lt;i&gt;really&lt;/i&gt; short and sweet, you can<a name="line.75"></a>
<FONT color="green">076</FONT>     *    take advantage of the JavaBean-style method accessors (see<a name="line.76"></a>
<FONT color="green">077</FONT>     *    below) and just write:&lt;/p&gt;<a name="line.77"></a>
<FONT color="green">078</FONT>     *<a name="line.78"></a>
<FONT color="green">079</FONT>     * &lt;pre&gt; HttpServletRequest req = C.mock(HttpServletRequest.class, new D() {<a name="line.79"></a>
<FONT color="green">080</FONT>     *    String requestURI = "www.myserver.com/myApp/myServlet";<a name="line.80"></a>
<FONT color="green">081</FONT>     * });&lt;/pre&gt;<a name="line.81"></a>
<FONT color="green">082</FONT>     *<a name="line.82"></a>
<FONT color="green">083</FONT>     * &lt;h2&gt;JavaBean-style method accessors&lt;/h2&gt;<a name="line.83"></a>
<FONT color="green">084</FONT>     *<a name="line.84"></a>
<FONT color="green">085</FONT>     * &lt;p&gt; CheesyMock recognizes JavaBean-style accessor methods in your<a name="line.85"></a>
<FONT color="green">086</FONT>     *    interfaces and automatically tries to match them against the<a name="line.86"></a>
<FONT color="green">087</FONT>     *    members of your delegate object. For example, if you have<a name="line.87"></a>
<FONT color="green">088</FONT>     *    following interface:&lt;/p&gt;<a name="line.88"></a>
<FONT color="green">089</FONT>     *<a name="line.89"></a>
<FONT color="green">090</FONT>     * &lt;pre&gt; public interface Example {<a name="line.90"></a>
<FONT color="green">091</FONT>     *    public String getName();<a name="line.91"></a>
<FONT color="green">092</FONT>     *    public void setName(String name);<a name="line.92"></a>
<FONT color="green">093</FONT>     * }&lt;/pre&gt;<a name="line.93"></a>
<FONT color="green">094</FONT>     *<a name="line.94"></a>
<FONT color="green">095</FONT>     * &lt;p&gt; then you will be able to declare your delegate as simple as<a name="line.95"></a>
<FONT color="green">096</FONT>     * this:&lt;/p&gt;<a name="line.96"></a>
<FONT color="green">097</FONT>     *<a name="line.97"></a>
<FONT color="green">098</FONT>     * &lt;pre&gt; Example mock = Cheesy.mock(Example.class, new Object() {<a name="line.98"></a>
<FONT color="green">099</FONT>     *   String name = "foo";<a name="line.99"></a>
<FONT color="green">100</FONT>     * });<a name="line.100"></a>
<FONT color="green">101</FONT>     * mock.getName(); // returns "foo"<a name="line.101"></a>
<FONT color="green">102</FONT>     * mock.setName("bar"); <a name="line.102"></a>
<FONT color="green">103</FONT>     * mock.getName(); // returns "bar"&lt;/pre&gt;<a name="line.103"></a>
<FONT color="green">104</FONT>     *<a name="line.104"></a>
<FONT color="green">105</FONT>     * &lt;h2&gt;The check() method&lt;/h2&gt;<a name="line.105"></a>
<FONT color="green">106</FONT>     * <a name="line.106"></a>
<FONT color="green">107</FONT>     * &lt;p&gt; CheesyMock employs a simple lifecycle model for mock objects:<a name="line.107"></a>
<FONT color="green">108</FONT>     *<a name="line.108"></a>
<FONT color="green">109</FONT>     * &lt;ol&gt; <a name="line.109"></a>
<FONT color="green">110</FONT>     *<a name="line.110"></a>
<FONT color="green">111</FONT>     * &lt;li&gt;&lt;p&gt;Create the mock using {@link Cheesy#mock()} or other equivalent<a name="line.111"></a>
<FONT color="green">112</FONT>     * method. During this stage you may get exceptions if your delegate<a name="line.112"></a>
<FONT color="green">113</FONT>     * object is not accepted by the current set of validators. For<a name="line.113"></a>
<FONT color="green">114</FONT>     * example, if you are using the 'strict' validators and implement a<a name="line.114"></a>
<FONT color="green">115</FONT>     * method in your delegate that is not in the interface, you will get<a name="line.115"></a>
<FONT color="green">116</FONT>     * an {@link java.lang.IllegalArgumentException}.&lt;/p&gt;&lt;/li&gt;<a name="line.116"></a>
<FONT color="green">117</FONT>     *<a name="line.117"></a>
<FONT color="green">118</FONT>     * &lt;li&gt;&lt;p&gt;Use the mock objects in your tests; call various methods, use<a name="line.118"></a>
<FONT color="green">119</FONT>     * getters and setterns and so on. As above, the chosen validators may<a name="line.119"></a>
<FONT color="green">120</FONT>     * throw exceptions. For example, with the 'strict' validators you<a name="line.120"></a>
<FONT color="green">121</FONT>     * will get an {@link java.lang.UnsupportedOperationException} if you<a name="line.121"></a>
<FONT color="green">122</FONT>     * call a method on the mock object that is not defined by the<a name="line.122"></a>
<FONT color="green">123</FONT>     * delegate.&lt;/p&gt;&lt;/li&gt;<a name="line.123"></a>
<FONT color="green">124</FONT>     *<a name="line.124"></a>
<FONT color="green">125</FONT>     * &lt;li&gt;&lt;p&gt;Finally, after you are done with the mock object you may call<a name="line.125"></a>
<FONT color="green">126</FONT>     * {@link Cheesy.check()} once to check its integrity. This is<a name="line.126"></a>
<FONT color="green">127</FONT>     * optional, but highly recommended. As above, you may get exceptions<a name="line.127"></a>
<FONT color="green">128</FONT>     * during this stage. For example, if you are using the 'strict'<a name="line.128"></a>
<FONT color="green">129</FONT>     * validators you will get an exception if you have not called all<a name="line.129"></a>
<FONT color="green">130</FONT>     * methods defined in the delegate object.&lt;/p&gt;<a name="line.130"></a>
<FONT color="green">131</FONT>     *<a name="line.131"></a>
<FONT color="green">132</FONT>     * &lt;p&gt;Additionally, any method annotated with {@link Check} in the<a name="line.132"></a>
<FONT color="green">133</FONT>     * delegate object will be invoked. This is a convenient way to<a name="line.133"></a>
<FONT color="green">134</FONT>     * perform custom validation of the delegate object, for example<a name="line.134"></a>
<FONT color="green">135</FONT>     * checking that the internal state is as expected.&lt;/p&gt;&lt;/li&gt;<a name="line.135"></a>
<FONT color="green">136</FONT>     *<a name="line.136"></a>
<FONT color="green">137</FONT>     * &lt;/ol&gt;<a name="line.137"></a>
<FONT color="green">138</FONT>     *<a name="line.138"></a>
<FONT color="green">139</FONT>     * &lt;h2&gt;Validators&lt;/h2&gt;<a name="line.139"></a>
<FONT color="green">140</FONT>     *<a name="line.140"></a>
<FONT color="green">141</FONT>     * TBA<a name="line.141"></a>
<FONT color="green">142</FONT>     *<a name="line.142"></a>
<FONT color="green">143</FONT>     * &lt;h2&gt;Mocking regular java classes&lt;/h2&gt;<a name="line.143"></a>
<FONT color="green">144</FONT>     *<a name="line.144"></a>
<FONT color="green">145</FONT>     * &lt;p&gt;CheesyMock can be used to create mock objects from regular java<a name="line.145"></a>
<FONT color="green">146</FONT>     *    classes, something which is not possible using the dynamic proxy<a name="line.146"></a>
<FONT color="green">147</FONT>     *    mechanism in the JDK. For this to work, you need a recent<a name="line.147"></a>
<FONT color="green">148</FONT>     *    version of CGLIB (http://cglib.sourceforge.net/) on the class<a name="line.148"></a>
<FONT color="green">149</FONT>     *    path at runtime.&lt;/p&gt;<a name="line.149"></a>
<FONT color="green">150</FONT>     *<a name="line.150"></a>
<FONT color="green">151</FONT>     * &lt;h2&gt;Dependencies&lt;/h2&gt;<a name="line.151"></a>
<FONT color="green">152</FONT>     *<a name="line.152"></a>
<FONT color="green">153</FONT>     * &lt;p&gt;Version 1.0 used log4j in some places, but for version 1.1 this<a name="line.153"></a>
<FONT color="green">154</FONT>     *    dependency has been removed. Other than that, CheesyMock doesn't<a name="line.154"></a>
<FONT color="green">155</FONT>     *    depend on any external jars at all.&lt;/p&gt;<a name="line.155"></a>
<FONT color="green">156</FONT>     *<a name="line.156"></a>
<FONT color="green">157</FONT>     * &lt;p&gt;As mentioned above, you need CGLIB on the class path if you<a name="line.157"></a>
<FONT color="green">158</FONT>     *    intend to mock regular classes. CheesyMock works fine without<a name="line.158"></a>
<FONT color="green">159</FONT>     *    it, but you are then restricted to creating mocks from<a name="line.159"></a>
<FONT color="green">160</FONT>     *    interfaces only.&lt;/p&gt;<a name="line.160"></a>
<FONT color="green">161</FONT>     *<a name="line.161"></a>
<FONT color="green">162</FONT>     * @see C<a name="line.162"></a>
<FONT color="green">163</FONT>     * @see Delegate<a name="line.163"></a>
<FONT color="green">164</FONT>     * @see D<a name="line.164"></a>
<FONT color="green">165</FONT>     * @author fredrik<a name="line.165"></a>
<FONT color="green">166</FONT>     */<a name="line.166"></a>
<FONT color="green">167</FONT>    public class Cheesy {<a name="line.167"></a>
<FONT color="green">168</FONT>            private static ProxyFactory factory = new SimpleProxyFactory();<a name="line.168"></a>
<FONT color="green">169</FONT>            private static final DefaultReturn defaultReturn = new NullDefaultReturn();<a name="line.169"></a>
<FONT color="green">170</FONT>    <a name="line.170"></a>
<FONT color="green">171</FONT>            static {<a name="line.171"></a>
<FONT color="green">172</FONT>                    try {<a name="line.172"></a>
<FONT color="green">173</FONT>                            Class.forName("net.sf.cglib.proxy.Enhancer");<a name="line.173"></a>
<FONT color="green">174</FONT>                            factory = new CGLIBProxyFactory();<a name="line.174"></a>
<FONT color="green">175</FONT>                    }<a name="line.175"></a>
<FONT color="green">176</FONT>                    catch (ClassNotFoundException e) {<a name="line.176"></a>
<FONT color="green">177</FONT>                    }<a name="line.177"></a>
<FONT color="green">178</FONT>            }<a name="line.178"></a>
<FONT color="green">179</FONT>            <a name="line.179"></a>
<FONT color="green">180</FONT>            protected Cheesy() {<a name="line.180"></a>
<FONT color="green">181</FONT>            }<a name="line.181"></a>
<FONT color="green">182</FONT>    <a name="line.182"></a>
<FONT color="green">183</FONT>            public static &lt;T&gt; T mock(Class&lt;T&gt; interfaceToImplement, Validator[] validators, Object delegate, <a name="line.183"></a>
<FONT color="green">184</FONT>                            DefaultReturn defaultReturn) {<a name="line.184"></a>
<FONT color="green">185</FONT>                    return (T) factory.newProxy(interfaceToImplement, validators, delegate, defaultReturn);<a name="line.185"></a>
<FONT color="green">186</FONT>            }<a name="line.186"></a>
<FONT color="green">187</FONT>    <a name="line.187"></a>
<FONT color="green">188</FONT>            /**<a name="line.188"></a>
<FONT color="green">189</FONT>             * Create a mock object with a 'normal' set of validators.<a name="line.189"></a>
<FONT color="green">190</FONT>             */<a name="line.190"></a>
<FONT color="green">191</FONT>            public static &lt;T&gt; T mock(Class&lt;T&gt; interfaceToImplement, Object delegate) {<a name="line.191"></a>
<FONT color="green">192</FONT>                    return mock(interfaceToImplement, <a name="line.192"></a>
<FONT color="green">193</FONT>                                    new Validator[] {<a name="line.193"></a>
<FONT color="green">194</FONT>                                            new StrictMethodOverride(),<a name="line.194"></a>
<FONT color="green">195</FONT>                                            new StrictPropertyOverride(),<a name="line.195"></a>
<FONT color="green">196</FONT>                                            new CheckDelegate()},<a name="line.196"></a>
<FONT color="green">197</FONT>                                    delegate, defaultReturn);<a name="line.197"></a>
<FONT color="green">198</FONT>            }<a name="line.198"></a>
<FONT color="green">199</FONT>    <a name="line.199"></a>
<FONT color="green">200</FONT>            /**<a name="line.200"></a>
<FONT color="green">201</FONT>             * Create a mock object with a 'normal' set of validators.<a name="line.201"></a>
<FONT color="green">202</FONT>             */<a name="line.202"></a>
<FONT color="green">203</FONT>            public static &lt;T&gt; T mock(Class&lt;T&gt; interfaceToImplement) {<a name="line.203"></a>
<FONT color="green">204</FONT>                    return mock(interfaceToImplement, null);<a name="line.204"></a>
<FONT color="green">205</FONT>            }<a name="line.205"></a>
<FONT color="green">206</FONT>    <a name="line.206"></a>
<FONT color="green">207</FONT>    <a name="line.207"></a>
<FONT color="green">208</FONT>            /**<a name="line.208"></a>
<FONT color="green">209</FONT>             * Create a mock object with a 'strict' set of validators.<a name="line.209"></a>
<FONT color="green">210</FONT>             */<a name="line.210"></a>
<FONT color="green">211</FONT>            public static &lt;T&gt; T mockStrict(Class&lt;T&gt; interfaceToImplement, Object delegate) {<a name="line.211"></a>
<FONT color="green">212</FONT>                    return mock(interfaceToImplement, <a name="line.212"></a>
<FONT color="green">213</FONT>                                    new Validator[] {<a name="line.213"></a>
<FONT color="green">214</FONT>                                            new StrictMethodOverride(),<a name="line.214"></a>
<FONT color="green">215</FONT>                                            new StrictPropertyOverride(),<a name="line.215"></a>
<FONT color="green">216</FONT>                                            new MandatoryInvocation(),<a name="line.216"></a>
<FONT color="green">217</FONT>                                            new MissingMethod(),<a name="line.217"></a>
<FONT color="green">218</FONT>                                            new CheckDelegate()},<a name="line.218"></a>
<FONT color="green">219</FONT>                                    delegate, defaultReturn);<a name="line.219"></a>
<FONT color="green">220</FONT>            }<a name="line.220"></a>
<FONT color="green">221</FONT>    <a name="line.221"></a>
<FONT color="green">222</FONT>            /**<a name="line.222"></a>
<FONT color="green">223</FONT>             * Create a mock object with a 'strict' set of validators.<a name="line.223"></a>
<FONT color="green">224</FONT>             */<a name="line.224"></a>
<FONT color="green">225</FONT>            public static &lt;T&gt; T mockStrict(Class&lt;T&gt; interfaceToImplement) {<a name="line.225"></a>
<FONT color="green">226</FONT>                    return mockStrict(interfaceToImplement, null);<a name="line.226"></a>
<FONT color="green">227</FONT>            }<a name="line.227"></a>
<FONT color="green">228</FONT>    <a name="line.228"></a>
<FONT color="green">229</FONT>            /**<a name="line.229"></a>
<FONT color="green">230</FONT>             * Create a mock object without any validation except for {@link CheckDelegate}.<a name="line.230"></a>
<FONT color="green">231</FONT>             */<a name="line.231"></a>
<FONT color="green">232</FONT>            public static &lt;T&gt; T mockRelaxed(Class&lt;T&gt; interfaceToImplement, Object delegate) {<a name="line.232"></a>
<FONT color="green">233</FONT>                    return mock(interfaceToImplement, <a name="line.233"></a>
<FONT color="green">234</FONT>                                    new Validator[] {<a name="line.234"></a>
<FONT color="green">235</FONT>                                            new CheckDelegate()},<a name="line.235"></a>
<FONT color="green">236</FONT>                                    delegate, defaultReturn);<a name="line.236"></a>
<FONT color="green">237</FONT>            }<a name="line.237"></a>
<FONT color="green">238</FONT>    <a name="line.238"></a>
<FONT color="green">239</FONT>            /**<a name="line.239"></a>
<FONT color="green">240</FONT>             * Create a mock object without any validation except for {@link CheckDelegate}.<a name="line.240"></a>
<FONT color="green">241</FONT>             */<a name="line.241"></a>
<FONT color="green">242</FONT>            public static &lt;T&gt; T mockRelaxed(Class&lt;T&gt; interfaceToImplement) {<a name="line.242"></a>
<FONT color="green">243</FONT>                    return mockRelaxed(interfaceToImplement, null);<a name="line.243"></a>
<FONT color="green">244</FONT>            }<a name="line.244"></a>
<FONT color="green">245</FONT>    <a name="line.245"></a>
<FONT color="green">246</FONT>            /**<a name="line.246"></a>
<FONT color="green">247</FONT>             * Check the state of a previously instantiated and used mock object.<a name="line.247"></a>
<FONT color="green">248</FONT>             *<a name="line.248"></a>
<FONT color="green">249</FONT>             * @param mocks one or more mock objects<a name="line.249"></a>
<FONT color="green">250</FONT>             */<a name="line.250"></a>
<FONT color="green">251</FONT>            public static void check(Object... mocks) {<a name="line.251"></a>
<FONT color="green">252</FONT>                    for(Object mock: mocks) {<a name="line.252"></a>
<FONT color="green">253</FONT>                            Object obj = factory.getHandler(mock);<a name="line.253"></a>
<FONT color="green">254</FONT>                            if (!(obj instanceof Mock)) {<a name="line.254"></a>
<FONT color="green">255</FONT>                                    throw new IllegalArgumentException("Can only check objects of cheesymock.Mock");<a name="line.255"></a>
<FONT color="green">256</FONT>                            }<a name="line.256"></a>
<FONT color="green">257</FONT>                            try {<a name="line.257"></a>
<FONT color="green">258</FONT>                                    ((Mock)obj).check();<a name="line.258"></a>
<FONT color="green">259</FONT>                            }<a name="line.259"></a>
<FONT color="green">260</FONT>                            catch (RuntimeException e) {<a name="line.260"></a>
<FONT color="green">261</FONT>                                    throw toRuntimeException(e);<a name="line.261"></a>
<FONT color="green">262</FONT>                            }<a name="line.262"></a>
<FONT color="green">263</FONT>                    }<a name="line.263"></a>
<FONT color="green">264</FONT>            }<a name="line.264"></a>
<FONT color="green">265</FONT>    }<a name="line.265"></a>




























































</PRE>
</BODY>
</HTML>
